extends Node2D

enum {S_draw,S_idle,S_follow,S_confirm,S_disCard}
var state=S_draw setget setState
var large=0 setget setLarge
var card

var targetPosition=Vector2(0,0)
var speed=500

onready var view=$CardView


func setLarge(value):
	large=value
	match large:
		0:
			scale=Vector2(0.5,0.5)
		1:
			scale=Vector2(0.8,0.8)

func setState(value):
	#刚抽到手牌
	
	match state:
		S_draw:
			$Area2D.collision_layer=2
		S_confirm:
			pass
	
	state=value
	
	match state:
		S_confirm:
			pass
			#targetPosition=Vector2(400,-100)
		S_disCard:
			$Area2D.collision_layer=0
			pass
	pass
	

func _ready():
	setLarge(0)

func _process(delta):
	match state:
		S_draw:
			goTarget(delta)
			if position==targetPosition:
				setState(S_idle)
				pass
			pass
		S_idle:
			goTarget(delta)
			pass
		S_follow:
			global_position=get_viewport().get_mouse_position()
			pass
		S_confirm:
			if card.useType<=2:
				goTarget(delta)
		S_disCard:
			position.y-=100*delta
			modulate.a-=delta
			if modulate.a<=0:
				#删除
				queue_free()
	
	
	pass
	
func _physics_process(delta):
	update()
func goTarget(delta):
	if  (targetPosition-position).length()>speed*delta:
		position+=(targetPosition-position).normalized()*speed*delta
	else:
		position=targetPosition
#丢弃
func discard():
	setState(S_disCard)
	pass
	
	
func loadCard(card_):
	view.loadCard(card_)
	card=card_
	

